﻿using System;
using System.Collections.Generic;

using System.Text;

namespace System.Qizx.Xml
{
    /// <summary>
    /// This class is used to encapsulate a source of Xml code in an single class.
    /// </summary>
    public class XmlSource
    {
        private System.IO.Stream bytes;
        private System.IO.StreamReader characters;
        private string uri;

        /// <summary>
        /// Constructs an empty XmlSource instance.
        /// </summary>
        public XmlSource()
        {
            bytes = null;
            characters = null;
            uri = null;
        }

        /// <summary>
        /// Constructs a XmlSource instance with the specified source System.IO.Stream.
        /// </summary>
        /// <param name="stream">The stream containing the document.</param>
        public XmlSource(System.IO.Stream stream)
        {
            bytes = stream;
            characters = null;
            uri = null;
        }

        public XmlSource(byte[] bytes) {
            this.bytes = new System.IO.MemoryStream(bytes);
            
        }

        /// <summary>
        /// Constructs a XmlSource instance with the specified source System.IO.StreamReader.
        /// </summary>
        /// <param name="reader">The reader containing the document.</param>
        public XmlSource(System.IO.StreamReader reader)
        {
            bytes = null;
            characters = reader;
            uri = null;
        }

        /// <summary>
        /// Construct a XmlSource instance with the specified source Uri string.
        /// </summary>
        /// <param name="source">The source containing the document.</param>
        public XmlSource(string source)
        {
            bytes = null;
            characters = null;
            uri = source;
        }

        /// <summary>
        /// Represents the source Stream of the XmlSource.
        /// </summary>
        public System.IO.Stream Bytes
        {
            get
            {
                return bytes;
            }
            set
            {
                bytes = value;
            }
        }

        /// <summary>
        /// Represents the source StreamReader of the XmlSource.
        /// </summary>
        public System.IO.StreamReader Characters
        {
            get
            {
                return characters;
            }
            set
            {
                characters = value;
            }
        }

        /// <summary>
        /// Represents the source URI of the XmlSource.
        /// </summary>
        public string Uri
        {
            get
            {
                return uri;
            }
            set
            {
                uri = value;
            }
        }
    }
}
